﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

public partial class DptoMun_DptoMun : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["nit"] != null)
            Response.Redirect("/SUEWebSite/Error.aspx");
        //-------------------------Lineas Agregadas para la seguridad----------------------------------------------------
        else if (Session["nomUsr"] != null)
        {
            List<String> Permisos = (List<String>)Session["Permisos"];

            if (!Permisos.Contains(System.IO.Path.GetFileName(HttpContext.Current.Request.FilePath)))
                Response.Redirect("/SUEWebSite/Error.aspx");
            else
                rebind();

        }
        else Response.Redirect("/SUEWebSite/Principal.aspx");

        //-------------------------Lineas Agregadas para la seguridad----------------------------------------------------

        
    }


    protected void Submit1_ServerClick(object sender, EventArgs e)
    {
        if ((File1.PostedFile != null) && (File1.PostedFile.ContentLength > 0))
        {

            string fn = System.IO.Path.GetFileName(File1.PostedFile.FileName);

           Label1.Text = "file name" + fn;
            string SaveLocation = Server.MapPath("Data") + "\\" + fn;

            if (fn == "dptos.xml" || fn == "municpios.xml")
            {
                try
                {
                    File1.PostedFile.SaveAs(SaveLocation);
                    Label1.Text = ("Archivo subido con éxito");
                }
                catch (Exception ex)
                {
                    Label1.Text = ("Error: " + ex.Message);
                }
            }
            else
            {
                Label1.Text = ("Error: Archivo no valido ");
            }
        }
        else
        {
            Label1.Text = ("Seleccione un archivo");
        }
        rebind();
    }
    private void rebind()
    {
        DirectoryInfo mydir = new DirectoryInfo(Server.MapPath("Data"));
        articleList.DataSource = mydir.GetFiles();
        articleList.DataBind();
    }
}
